package top.resty.erp.dao;

import org.apache.ibatis.annotations.*;
import top.resty.erp.domain.Products;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年03月23 13:53
 */
@Mapper
public interface IProducts {
	
	@Insert({"<script>",
			"insert into tb_products values",
			"<foreach  collection='products' item='item' index='index' separator=','>",
			"(null,#{item.standard},#{item.units},#{item.count},#{item.price},#{item.money},#{item.supplier}," +
					"#{item.contact},#{item.telephone},#{item.createTime},#{item.brandName},#{item.varietyName}," +
					"#{item.typeName},#{item.warehouseId},",
			"#{item.remake})",
			"</foreach>",
			"</script>"
	})
	public int saveProducts(@Param("products") List<Products> products);
	
	@Select("select distinct supplier from tb_products")
	public List<String> findAllSuppliers();
	
	@Select("select distinct variety_name from tb_products")
	public List<String> findAllVarieties();
	
	
	@Select("select distinct contact from tb_products where supplier = #{supplier}")
	public List<String> findAllContactsForSupplier(String supplier);
	
	@Select("select distinct telephone from tb_products where contact = #{contact}")
	public List<String> findTelephonesForContact(String contact);
	
	
	@Select("select distinct warehouse_id from tb_products where warehouse_id like '%${warehouseId}%'")
	public List<String> findByLikeWarehouseId(String warehouseId);
	
	
	@Select({"<script>" +
			"select id,standard,units,count,price,money,supplier,contact,telephone,create_time as createTime,brand_name as brandName,variety_name as varietyName,type_name as typeName,warehouse_id as warehouseId,remake from tb_products " +
			"<if test='warehouseId != null and warehouseId !=\"\"'>" +
			"where warehouse_id = #{warehouseId}" +
			"</if>" +
			"</script>"})
	public List<Products> warehouseIdList(@Param("warehouseId") String warehouseId);
	
	
	@Update("update tb_products set ${arg0} = #{arg1} where id = #{arg2}")
	public int updateProducts(String keyStr,String valueStr,Integer id);
	
	
	@Delete("delete from tb_products where id = #{id}")
	public int deleteProduct(Integer id);
	
	@Select("select id,standard,units,count,price,money,supplier,contact,telephone,create_time as createTime," +
			"brand_name as brandName,variety_name as varietyName,type_name as typeName,warehouse_id as warehouseId," +
			"remake from tb_products where warehouse_id = #{warehouseId}")
	public List<Products> warehouseIdAllList(String warehouseId);
	
	@Select("select id,standard,units,count,price,money,supplier,contact,telephone,create_time as createTime,brand_name as brandName,variety_name as varietyName,type_name as typeName,warehouse_id as warehouseId,remake from tb_products where supplier = #{supplier}")
	public List<Products> findProductsForSupplier(String supplier);
	
	@Select("select id,standard,units,count,price,money,supplier,contact,telephone,create_time as createTime," +
			"brand_name as brandName,variety_name as varietyName,type_name as typeName,warehouse_id as warehouseId," +
			"remake from tb_products where variety_name = #{variety}")
	public List<Products> findProductsForVariety(@Param("variety") String variety);
	
}
